package extreme.refactor.gilded_rose;

public class Item {

    public static final String AGED_BRIE = "Aged Brie";
    public static final String BACKSTAGE_PASS = "Backstage pass";
    public static final String SULFURAS = "Sulfuras";
    public String name;
    public int sellIn;
    public int quanlity;

    public Item(String name, Integer sellIn, Integer quanlity) {
        this.name = name;
        this.sellIn = sellIn;
        this.quanlity = quanlity;
    }

    @Override
    public String toString() {
        return this.name + ", " + this.sellIn + ", " + this.quanlity;
    }

    protected Item doUpdateQuality(Item item) {
        if (item.name.equals(AGED_BRIE)) {
            return Aged.getAged(item);
        } else if (item.name.equals(BACKSTAGE_PASS)) {
            return Backstage.getBackstage(item);
        } else if (item.name.equals(SULFURAS)) {
            return Sulfuras.getSulfuras(item);
        } else
            return Item.getItem(item);
    }

    private static Item getItem(Item item) {
        if (item.quanlity > 0) {
            item.quanlity = item.quanlity - 1;
        }
        item.sellIn = item.sellIn - 1;
        if (item.sellIn < 0) {
            if (item.quanlity > 0) {
                item.quanlity = item.quanlity - 1;
            }
        }
        return item;
    }
}
